﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2013  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_GLES_RENDER_BUFFER_H
#define _UXS_GLES_RENDER_BUFFER_H

#include "GLESStateManager.h"

namespace UX_STL
{
namespace GLESshell
{

	//
	// Render Target
	//

	class GLESRenderTarget : public GLESBaseObject
	{
	protected:
		uvec3				_vDimension;
		gl_rt_format::type	_eIFormat;

	public:
		GLESRenderTarget(): _vDimension(), _eIFormat(gl_rt_format::_UNKNOWN) {}

		virtual void Attach(GLESFrameBuffer *pFBO, gl_fbo_attach::type eAttach, uint uLevel = 0) = 0;
		virtual bool Create(gl_rt_format::type eFormat, const uvec3 &vDim, uint8 uSamples = 0) = 0;
		
		const uvec3 &		Dimension()			const	{ return _vDimension; }
		gl_rt_format::type	InternalFormat()	const	{ return _eIFormat; }
	};



	//
	// Render Buffer
	//

	class GLESRenderBuffer : public GLESRenderTarget
	{
	private:
		GLuint		_uID;

	public:
		GLESRenderBuffer();
		~GLESRenderBuffer();
		
		// GLRenderTarget //
		virtual void Attach(GLESFrameBuffer *pFBO, gl_fbo_attach::type eAttach, uint uLevel = 0);
		virtual bool Create(gl_rt_format::type eFormat, const uvec3 &vDim, uint8 uSamples = 0);
		
		bool  Create(const uvec2 &vDim, gl_rt_format::type eIFormat, uint uSamples = 0);
		void  Destroy();

		void  Bind()	const;
		void  Unbind()	const;

		GLuint	Id()		const		{ return _uID; }
		GLenum	Target()	const		{ return GL_RENDERBUFFER; }
	};


	
//------------------------- GLESRenderBuffer ----------------------//
/*
=================================================
	установить текущий рендербуфер
=================================================
*/
	inline void GLESRenderBuffer::Bind() const
	{
		GL_CALL( SMAN()->BindRenderbuffer( _uID ) );
	}
	
/*
=================================================
	установить дефолтовый рендербуфер
=================================================
*/
	inline void GLESRenderBuffer::Unbind() const
	{
		GL_CALL( SMAN()->BindRenderbuffer( 0 ) );
	}

//-------------------------------------------------------------------

}	// GLESshell
}	// UX_STL

#endif	// _UXS_GLES_RENDER_BUFFER_H